import IView, {Message, Modal} from 'view-design';
import 'view-design/dist/styles/iview.css';
import {WebStorage} from "jboot-env";
import methods from './methods/index';
import httpConfig from './http/index';
import routerConfig from './router/index';
import VXETable from 'vxe-table';
import 'vxe-table/lib/style.css';
import 'xe-utils';

export default function (options) {
	options
		.checkVersion()
		.install(IView)
		.install(VXETable)
		.upload({
			base: {
				url: '/__api/sys/attachment/upload',
				nameField: 'oldname',
				urlField: 'attachment',
				headers: {
					'token': new Promise(resolve => {
						WebStorage.localMode().get('{PROJECT_NAME}-token').then(resolve).catch(() => {});
					})
				}
			}
		})
		.methods(methods)
		.components(require.context('./components', false, /\.vue/))
		.store()
		.http(config => httpConfig(config, options))
		.router(config => routerConfig(config, options))
		.tips(config => config
			.success(message => Message.success({content: message}))
			.info(message => Message.info({content: message}))
			.warning(message => Modal.warning({title: '温馨提示', content: message}))
			.error(message => Modal.error({title: '操作异常', content: message}))
		)
		.mappings(config => config.pageResponse({pageNum: 'pageNum', pageSize: 'pageSize', total: 'total', data: 'list'}))
		.build();
}
